package src;
import java.util.Comparator;

/*
 * Created on Nov 24, 2009
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author Danish Contractor (dcontrac@in.ibm.com)
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class Token extends Object {

	public String token;

	public float probability;

	public String getWord() {
		return token;
	}

	public float getScore() {
		return probability;
	}

	public Token(String word, float f) {
		token = word;
		probability = f;
	}

	public String toString() {
		return token + " " + Float.toString(probability);
	}
	
	public void normalizeWeight(float normalizationWeight){
		probability = probability/normalizationWeight;
	}
//	 COMPARATOR FOR TOKEN OBJECT
	public static Comparator DecreasingOrderOfScores() {
		class CompareSuggestedWordByDescendingScores implements Comparator {

			public int compare(Object w1, Object w2) {
				Token ws1 = (Token) w1;
				Token ws2 = (Token) w2;
				if (ws1.getScore() < ws2.getScore())
					return 1;
				else if (ws1.getScore() > ws2.getScore())
					return -1;
				else
					return 0;
			}

			public boolean equals(Token w1, Token w2) {
				if (w1.getScore() == w2.getScore())
					return true;
				else
					return false;
			}

		}
		return new CompareSuggestedWordByDescendingScores();
	}

}